<template>
    <h2>查看详情</h2>
    <table>
        <tr>
            <td>真实姓名</td>
            <td>
            <input type="text" placeholder="请输入真实姓名" v-model="info.Gname">
            </td>
        </tr>
        
        <tr>
            <td>性别</td>
            <td>
            <input type="radio" placeholder="请输入性别" v-model="info.Gsex" value="男">男
            <input type="radio" placeholder="请输入性别" v-model="info.Gsex" value="女">女
            </td>
        </tr>
        <tr>
            <td>手机号</td>
            <td>
            <input type="text" placeholder="请输入手机号" v-model="info.Gphone">
            </td>
        </tr>
        <tr>
            <td>身份证</td>
            <td>
            <input type="text" placeholder="请输入身份证" v-model="info.Gsfz">
            </td>
        </tr>
        <tr>
            <td>工资</td>
            <td>
            <input type="text" placeholder="请输入工资" v-model="info.Gprice">
            </td>
        </tr>
        <tr>
            <td>类型</td>
            <td>
            <select v-model="info.Tid">
            <option value="0">--请选择--</option>
            <option v-for="itme in BDinfo" :value="itme.Tid">{{ itme.Tname }}</option>
            
            </select>
            </td>
        </tr>
        <tr>
            
            <td colspan="2">
            <input type="button" value="提交" @click="addall">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { onMounted } from "vue"
import { useRoute } from "vue-router"
import axios from "axios"
import { useRouter } from "vue-router"

const router = useRouter()
const route = useRoute()




const BDinfo = ref([{
  Tid:0,
  Tname:"",
}])

//生命周期函数勾
onMounted(() => {
  Bind();
})


const Bind = () => {
  axios.get("http://localhost:53393/api/User/BindUser")
  .then((res) => {
    BDinfo.value=res.data
    console.log(BDinfo.value);
  })
  .catch((err) => {
    console.log(err);
  })
}

const info = ref({
   Gname:"",
   Gsex:"",
   Gphone:"",
   Gsfz:"",
   Gprice:"",
   Tid:"",
})

const addall = () => {
  
  const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  if (!reg.test(info.value.Gsfz)) {
    alert("身份证输入不合法");
    return false;
  }

  const phone = /^1[3456789]\d{9}$/
  if (!phone.test(info.value.Gphone)) {
    alert("手机号输入不合法");
    return false;
  }
  axios.post("http://localhost:53393/api/User/Addsume",
    
  {
    Uid:route.query.Uid,
    Gname:info.value.Gname,
    Gsex:info.value.Gsex,
    Gphone:info.value.Gphone,
    Gsfz:info.value.Gsfz,
    Gprice:info.value.Gprice,
    Tid:info.value.Tid,
  }
  )
  .then((res) => {
    if(res.data>0){
      alert("添加成功")
      
    }
    else{
        alert("添加失败")
    }
        
    
  })
  .catch((err) => {
    console.log(err);
  })
}


</script>